import action from '../utils/action';
import request from '../utils/request';
import { storage } from '@doctorwork/saga';

export default {
    namespace: 'web',
    state: { url: '' },
    reducers: {
        save(state, { payload }) {
            return Object.assign({}, state, payload);
        },
        saveMore(state, { payload: list }) {
            return { ...state, feed: [...state.list, ...list] };
        }
    },
    effects: {
        *setUrl({ payload }, { put }) {
            const authToken = yield put.resolve(storage.get('authToken'));
            if (!authToken) {
                put({ type: '$error/auth', payload: {} });
                return;
            }
            let { decodeUrl } = payload;
            decodeUrl +=
                decodeUrl.indexOf('?') >= 0
                    ? `&authToken=${authToken}`
                    : `?authToken=${authToken}`;
            console.log('跳转H5的Url:', decodeUrl);
            yield put({
                type: 'save',
                payload: { url: decodeUrl }
            });
        }
    }
};
